'use strict'
var Koa = require('koa')
var path = require('path')
var wechat = require('./wechat/g')

var util = require('./lib/util')

var wechat_file = path.join(__dirname, './config/wechat.txt')

var config = {
  wechat: {
    appID : 'wx04a055f74d280d5b',
    appSecret: '7aef7b2360ee873bfdfbaf29dca88583',
    token: 'fanbingkun',
    getAccessToken: function(){
      return util.readFileAsync(wechat_file)
    },
    saveAccessToken: function(data){
      data = JSON.stringify(data)
      return util.writeFileAsync(wechat_file,data)
    }
  }
}

var app = new Koa()

app.use(wechat(config.wechat))

app.listen(8080)
console.log('服务器启动')